import _ from "lodash";

export default {

  setCusAppInfo: (state, { isAll, arr }) => {
    state.cusAppArray.isAll = isAll;
    let tar = state.cusAppArray;
    tar.arrId.splice(0, tar.arrId.length);
    for (let i in arr) {
      tar.arrId.push(arr[i])
    }
  },
  setCompanyEmplyoeeId(state, value) {
    state.conditional.companyEmployeeId = value;
  },
  setLoginInfo(state, loginMsg) {
    state.loginInfo = loginMsg;
  },
  setConditionalKeyValue: (state, { key, value }) => {
    if (_.isBoolean(state.conditional[key])) {
      state.conditional[key] = !state.conditional[key];
    }
    if (_.isNumber(state.conditional[key])) {
      state.conditional[key] = (state.conditional[key] == value) ? 0 : value
    }
  },
  setConditionalUnselftag: (state, { removeArr, addArr }) => {
    let tar = state.conditional.selftag;
    let utar = state.conditional.unselftag;
    removeArr.forEach((ov) => {
      let idx = tar.findIndex((v) => {
        return v === ov
      })
      if (idx > -1) {
        tar.splice(idx, 1)
      }
    })
    addArr.forEach((v) => {
      if (v != '') {
        utar.push(v)
      }
    });
  },
  setConditionalSelftag: (state, { borderArr, checkedArr, uncheckedArr, }) => {
    let tar = state.conditional.selftag;
    let utar = state.conditional.unselftag;
    if (checkedArr.length == 0 && uncheckedArr.length == 0) {
      borderArr.forEach((v) => {
        let idx1 = tar.findIndex((va) => { return va == v })
        if (idx1 > -1) { tar.splice(idx1, 1) }
        let idx2 = utar.findIndex((va) => { return va == v })
        if (idx2 > -1) { utar.splice(idx2, 1) }
      })
    } else {
      checkedArr.forEach((v) => {
        if (!tar.includes(v)) { tar.push(v) }
        let idx = utar.findIndex((va) => { return va == v })
        if (idx > -1) { utar.splice(idx, 1) }
      })
      uncheckedArr.forEach((v) => {
        if (!utar.includes(v)) { utar.push(v) }
        let idx = tar.findIndex((va) => { return va == v })
        if (idx > -1) { tar.splice(idx, 1) }
      })
    }
  },
  setConditionalJoinTime: (state, arrTime) => {
    state.conditional.isInTime = arrTime != null;
    state.conditional.inTimeBegin = _.get(arrTime, '[0]', '');
    state.conditional.inTimeEnd = _.get(arrTime, '[1]', '');
  },
  setConditionalFromSourceId: (state, arr) => {
    state.conditional.fromSourceId = arr.join(',');

  },

  resetConditional: (state) => {

    state.conditional.isStar = false;
    state.conditional.unread = 0;
    state.conditional.bubbling = 0;
    state.conditional.isOnlyNoReply = false;
    /* 首期存在，后来又不需要，现在（2022-8-31）又加上来的 */
    state.conditional.fromSourceId = '';
    state.conditional.isInTime = false;
    state.conditional.inTimeBegin = '';
    state.conditional.inTimeEnd = '';

  },//重置条件区


};